import Charts // !
import SwiftUI

struct Student: Identifiable {
    let id = UUID()
    var height: Double
    var name: String
}

struct ChartWithObject : View {
    @State var classroom: Array<Student> = [
        Student(height: 165.0, name: "Foo"),
        Student(height: 150.0, name: "Boo"),
        Student(height: 140.0, name: "John"),
        Student(height: 155.0, name: "Doe")
    ]
    
    var body: some View {
        VStack {
            Text("Chart with Object")
                .font(.largeTitle)
            
            
            Chart(classroom) {
                // $0 - 每一个 student
                // $0.height
                BarMark(
                    x: .value("Height", "\($0.height)"),
                    y: .value("Value", $0.height)
                )
            }
        }
        .padding()
    }
}
